package com.canxin.controller;

import com.alibaba.fastjson.JSONArray;
import com.canxin.entity.ScoreEntity;
import com.canxin.entity.StudentsEntity;
import com.canxin.service.BinduserServiceI;
import com.canxin.service.ScoreServiceI;
import com.canxin.service.StudentServiceI;
import org.apache.log4j.Logger;
import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.web.system.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import weixin.p3.oauth2.rule.RemoteWeixinMethod;
import weixin.util.WeiXinConstants;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**   
 * @Title: Controller
 * @Description: 成绩信息表
 * @author zhangdaihao
 * @date 2017-03-05 22:59:42
 * @version V1.0   
 *
 */
@Scope("prototype")
@Controller
@RequestMapping("/canxinController")
public class CanxinController extends BaseController {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(CanxinController.class);

	@Autowired
	private RemoteWeixinMethod remoteWeixinMethod;

	@Autowired
	private SystemService systemService;
	private String message;

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	@ResponseBody
	@RequestMapping(params = "getAuthorCode")
	public Map getTeacherAuthorPage(HttpServletRequest request,HttpServletResponse resp,@RequestParam String url) throws IOException
	{
		Map result = new HashMap();
		String returnUrl = remoteWeixinMethod.callWeixinAuthor2ReturnUrl(request,"gh_1f0d2b0c9291",url);
		if(returnUrl==null)
		{
			resp.sendRedirect(url);
			return result;
		}
		resp.sendRedirect(returnUrl);
		result.put("result","ok");
		return result;
	}

	@ResponseBody
	@RequestMapping(params = "getOpenIdByAuthorCode",produces="application/json;charset=UTF-8")
	public Map getTeacherAuthorCode(HttpServletRequest request,HttpServletResponse resp,@RequestParam String url) throws IOException
	{
		remoteWeixinMethod.callWeixinAuthor2ReturnUrl(request,"gh_1f0d2b0c9291",url);
		String openId =(String) request.getSession().getAttribute(WeiXinConstants.USER_OPENID);
		Map result = new HashMap();
		result.put("openId",openId);
		return result;
	}
}
